<?php


namespace app\api\controller;


use app\admin\model\UserMoneyLog;
use app\common\controller\Api;

class Recharge extends Api
{
    protected $noNeedLogin = ['collage'];
    protected $noNeedRight = ['*'];


    /***
     *
     * 充值
     */
    public function Recharge()
    {

    }

    public function index()
    {
        $user_id = $this->auth->id;
        $user = \app\admin\model\User::field('id,money,score,today_prize,all_prize,')
            ->find($user_id);
        $this->success('获取成功', $user);
    }

    /***
     *
     * 余额记录
     */
    public function log()
    {
        $page = input('page', 1);   //分页
        $type = input('type', '');   //类型
        $where = [];
        if (!empty($type)) {
            $where['status'] = ['=', $type];
        }
        $pinGou_log = UserMoneyLog::where(['user_id' => $this->auth->id])
            ->where('status', '<>', -2)
            ->where($where)
            ->field('id,type,status,money,memo,createtime')
            ->page($page, 10)
            ->select();
        foreach ($pinGou_log as $v) {
            if ($v['status'] == 1) {
                $v['money'] = '+' . $v['money'];
            } elseif ($v['status'] == -1) {
                $v['money'] = '-' . $v['money'];
            }
            $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
            //$v->unsetAppend();
        }
        $this->success('获取成功', $pinGou_log);
    }

}